package com.bytic.miaosha.config;

import com.bytic.miaosha.redis.RedisCusProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Configuration
@EnableConfigurationProperties(RedisCusProperties.class)
public class RedisConfig {

    @Autowired
    RedisCusProperties redisCusProperties;

    @Bean
    public JedisPool jedisPoolFactory() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(redisCusProperties.getPoolMaxIdle());
        config.setMaxTotal(redisCusProperties.getPoolMaxTotal());
        config.setMaxWaitMillis(redisCusProperties.getPoolMaxWait() * 1000);
        JedisPool jedisPool = new JedisPool(config, redisCusProperties.getHost(), redisCusProperties.getPort(),
                redisCusProperties.getTimeout());
        return jedisPool;
    }

}
